import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../AppConfig/Config.dart';
import '../../http/api.dart';
import '../../l10n/messages.dart';

class SetPaymentPassword extends StatefulWidget {
  const SetPaymentPassword({super.key});

  @override
  State<SetPaymentPassword> createState() => _SetPaymentPasswordState();
}

class _SetPaymentPasswordState extends State<SetPaymentPassword> {
  String passwordOne="";
  String passwordTwo="";
  @override
  Widget build(BuildContext context) {
    var messages = AppLocalizations.of(context)!;
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios, color: Colors.black),
          onPressed: () => Navigator.of(context).pop(),
        ),
        backgroundColor: Colors.white,
        centerTitle: true,
        title: Text("设置支付密码",style: TextStyle(color: Colors.black,fontWeight: FontWeight.w300,fontSize: 16.sp),),
      ),
      body: ListView(
        children: [
          Container(
            color:Color.fromRGBO(251, 236, 228, 1) ,
            padding: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h,bottom: 8.h),
            child:Text("支付密码用于钱包支付、修改绑定手机号等操作。为了资金安全，请牢记支付密码且不要透露给他人。",style: TextStyle(color: MyColors.themeColor,fontSize: 13.sp),),
          ),
          Container(
            color: Colors.white,
            height: 104.h,
            padding: EdgeInsets.only(left: 20.w,top: 10.h,bottom: 10.h),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text("输入密码",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                    SizedBox(width: 10.w,),
                    Container(
                      width: 200.w,
                      height: 35.h,
                      child:  TextField(

                        decoration: InputDecoration(
                          hintText: '请输入6位密码',
                          hintStyle:TextStyle(fontSize: 14.sp,color: MyColors.hintColor),
                          filled: true,
                          fillColor: Colors.white,
                          border: InputBorder.none,
                          alignLabelWithHint: true,

                        ),
                        obscureText: true,
                        keyboardType: TextInputType.number,
                        textAlign: TextAlign.left,
                        style: TextStyle(color: Colors.black),
                        onChanged: (value) {
                          setState(() {
                            if(value.length<7){
                              passwordOne=value;
                            }else{
                              BrnToast.show("密码长度为6位", context,);
                            }

                          });
                        },
                      ),
                    ),
                  ],
                ),
                Container(height: 1.h,color: MyColors.backgreyColor,),
                Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text("确认密码",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                    SizedBox(width: 10.w,),
                    Container(
                      width: 200.w,
                      height: 35.h,
                      child:  TextField(

                        decoration: InputDecoration(
                          hintText: '请输入6位密码',
                          hintStyle:TextStyle(fontSize: 14.sp,color: MyColors.hintColor),
                          filled: true,
                          fillColor: Colors.white,
                          border: InputBorder.none,
                          alignLabelWithHint: true,

                        ),
                        obscureText: true,
                        keyboardType: TextInputType.number,
                        textAlign: TextAlign.left,
                        style: TextStyle(color: Colors.black),
                        onChanged: (value) {
                          setState(() {
                            if(value.length<7){
                              passwordTwo=value;
                            }else{
                              BrnToast.show("密码长度为6位", context,);
                            }

                          });
                        },
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
          SizedBox(height: 50.h,),
          Container(margin: EdgeInsets.only(left: 15.w,right: 15.w),
            child:    BrnSmallMainButton(
              title: '提交',
              bgColor: MyColors.themeColor,
              fontSize: 16.sp,
              radius: 30,
              onTap: () {

                ApiManager.postData(
                  context,
                  'api/pay/shipper/user/resetPayPassword',
                  {
                    "clientType":"SHIPPER",
                    "password": passwordOne,
                    "rePassword": passwordTwo,
                  },
                      (responseData)  {
                    BrnToast.show("密码设置成功", context,);
                    Navigator.pop(context);
                    Navigator.pop(context,"success");
                  },
                );

              },
            ),
          ),

        ],
      ),
    );
  }
}
